package com.example.Blog.service;

import com.example.Blog.dao.CommentDao;
import com.example.Blog.model.Comment;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentService {
    final CommentDao commentDao;

    public CommentService(CommentDao commentDao) {
        this.commentDao = commentDao;
    }

    public Comment postComment(Comment comment) {
        return this.commentDao.save(comment);
    }

    public void likeComment(Comment comment) {
        this.commentDao.updateByCommentId(comment.getCommentLikes() + 1, comment.getCommentId());
    }

    public void deleteComment(int commentId) {
        this.commentDao.deleteByCommentId(commentId);
    }

    public void deleteByBelongToArticle(int articled){
        this.commentDao.deleteByCommentBelongToArticle(articled);
    }

    public List<Comment> findAllByCommentBelongToArticleOrderByCommentLikes(int articleId){
        return this.commentDao.findAllByCommentBelongToArticleOrderByCommentLikes(articleId);
    }
}
